package collection;

import exception.CollectionEmptyException;

public class Deque<E> implements IDeque<E>{

	private DLinkedList<E> internalList = new DLinkedList<E>();
	
	public Deque(){}
	
	@Override
	public boolean isEmpty() 
	{
		return this.internalList.isEmpty();
	}

	@Override
	public int size() 
	{
		return this.internalList.size();
	}

	@Override
	public E getFirst() throws CollectionEmptyException 
	{
		return this.internalList.getFirst().getElement();
	}

	@Override
	public E getLast() throws CollectionEmptyException 
	{
		return this.internalList.getLast().getElement();
	}

	@Override
	public void addFirst(E element) 
	{
		this.internalList.addFirst(this.internalList.createNode(element));
	}

	@Override
	public void addLast(E element) 
	{
		this.internalList.addLast(this.internalList.createNode(element));
	}

	@Override
	public E removeFirst() throws CollectionEmptyException 
	{
		return this.internalList.removeFirst().getElement();
	}

	@Override
	public E removeLast() throws CollectionEmptyException 
	{
		return this.internalList.removeLast().getElement();
	}
	
	@Override
	public String toString()
	{
		return this.internalList.toString();
	}

}
